<template>
  <div class="scroll-board" :class="fullheight ? 'full-height' : ''">
    <div class="scroll-header" v-if="title">
      <div>{{ title }}</div>
      <div class="stretch-width">
        <marqueeBoard :content="marquee" v-if="marquee" />
      </div>
    </div>
    <dv-scroll-board :config="config" @click="clickRow" ref="scrollboard" />
  </div>
</template>

<script>
import marqueeBoard from './scrollTable.vue';

export default {
  name: 'ScrollBoard',
  props: {
    scrollConfig: {
      type: Object,
      default: () => {}
    },
    title: {
      type: String,
      default: ''
    },
    fullheight: {
      type: Boolean,
      default: false
    },
    marquee: {
      type: String,
      default: ''
    }
  },
  components: {
    marqueeBoard
  },
  data () {
    return {
      config: {
        header: [],
        data: [],
        columnWidth: [],
        align: [],
        rowNum: 8,
        headerBGC: '#1981f6',
        headerHeight: 35,
        oddRowBGC: 'rgba(0, 44, 81, 0.8)',
        evenRowBGC: 'rgba(10, 29, 50, 0.8)',
        index: false,
        hoverPause: false,
        waitTime: 4000
      }
    }
  },
  methods: {
    clickRow (data) {
      this.$emit('click', data);
    },
    redraw () {
      this.$nextTick(() => {
        if (document.createEvent) {
          const event = document.createEvent('HTMLEvents');
          event.initEvent('resize', true, true);
          window.dispatchEvent(event);
        } else if (document.createEventObject) {
          window.fireEvent('onresize');
        }
      });
    }
  },
  computed: {
  },
  watch: {
    scrollConfig (val) {
      if (val) {
        this.config = { ...this.config, ...val };
        if (this.config.index) { // 序号
          this.config.columnWidth.unshift(50);
        }
        this.redraw();
      }
    },
    fullheight (val) {
      this.config = { ...this.config, rowNum: val ? 16 : 8 };
      this.redraw();
    }
  }
}
</script>

<style lang="scss">
.scroll-board {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: 0 0 3px blue;
  display: flex;
  flex-direction: column;
  background-color: rgba(6, 30, 93, 0.5);
  border-top: 2px solid rgba(1, 153, 209, .5);
  margin-bottom: 8px;

  .full-height {
    height: calc(50% - 4px)!important;
  }

  .scroll-header {
    font-size: 18px;
    font-weight: bold;
    padding: 10px;

    display: flex;
  }

  .stretch-width {
    display: flex;
    flex: 1;
    padding-left: 10px;
  }
}
</style>
